//
//  Demo2.c
//  Math05
//
//  Created by Xavier on 2023/11/8.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//2.编写高级语言程序，随机生产10万个整数，整数范围是【0,100000】，然后保存到数组里面。设计排序算法实现数组排序。试着分析算法的复杂度。
void Bubble(int arr[], long int len) {
    for (int i = 0; i < len; i++) {
        for (int j = 0; j < len - i - 1; j++) {
            if (arr[j] > arr[j+1]) {
                int tmp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = tmp;
            }
        }
    }
}
int main(int argc, const char * argv[]) {
//    time_t begin, end;
//    time(&begin);
    clock_t begin, end;
    begin = clock();
    
    srand((unsigned)time(NULL));
    int arr[100000] = {0};
    for (int i = 0; i < 100000; i++) {
        int num = rand()%100000+1;
        arr[i] = num;
        //printf("%d %d\n", i, num);
    }
    Bubble(arr, 100000);
//    for (int j = 0; j < 100000; j++) {
//        printf("%d ", arr[j]);
//    }
    
    //time(&end);
    end = clock();
    //time_t useTime = end - begin;
    double useTime = (double)end - begin;

    printf("Process is run of time:%f\n", useTime/1000);
}
